home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT7 / INPSTR.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-05-10  |  3.0 KB  |  64 lines

  1. ;
  2. ;       Program InpStr ( Chapter 7 )
  3. ;
  4. .model  small
  5. .stack
  6. .data
  7. CR      equ     0Dh
  8. LF      equ     0Ah
  9. Msg16   db      CR,LF, 'BIOS service: Type a string and press ENTER: '
  10.     db      CR,LF,'$'  
  11. Msg21   db      CR,LF, 'DOS service: Type a string and press ENTER: '
  12.     db      CR,LF,'$'  
  13. MsgOut  db      'The following text entered: ' ,'$'
  14. ReqInp  db      255
  15. FactInp db      0
  16. Str1    db      256 dup ('$')   
  17. .code
  18. .startup
  19. ;===    Output message about BIOS service
  20.     mov     ah,09                   ; function 09 - output text string
  21.     lea     dx,Msg16                ; address of message 'BIOS service'
  22.     int     21h                     ; DOS service call
  23. ;===    Creating string from characters (BIOS service)
  24.     mov     bx,0                    ; BX -  number of current character
  25. Next16: mov     ah,0                    ; function 00h - read character
  26.     int     16h                     ; BIOS keyboard service
  27.     cmp     al,0                    ; special key?
  28.     je      Next16                  ; ignore special key and read next
  29.     mov     Str1[bx],al             ; store current character into string
  30.     inc     bx                      ; increase counter to store next char 
  31.     cmp     al,CR                   ; ENTER key pressed (Carriage Return)?
  32.     jne     Next16                  ; if not, read next character
  33. ;===    Append characters CR and LF to the end of the string
  34.     mov     Str1[bx],LF             ; add Line Feed to the end of string
  35.     mov     Str1[bx+1],'$'          ; End Message character
  36. ;===    Output header and string entered        
  37.     mov     ah,09                   ; function 09 - output text string
  38.     lea     dx,MsgOut               ; address of message 'Text entered'
  39.     int     21h                     ; DOS service call
  40.     lea     dx,Str1                 ; address of string obtained
  41.     int     21h                     ; DOS service call
  42. ;===    Output message about DOS service        
  43.     mov     ah,09                   ; function 09 - output text string
  44.     lea     dx,Msg21                ; address of message 'BIOS service'
  45.     int     21h                     ; DOS service call
  46. ;===    Input text string (DOS service)
  47.     mov     ah,0Ah                  ; function 0Ah - input text string
  48.     lea     dx,ReqInp               ; DS:DX - address of input buffer 
  49.     int     21h                     ; DOS service call
  50. ;===    Append characters CR and LF to the end of the string    
  51.     mov     bl,FactInp              ; length of string actually read
  52.     mov     bh,0                    ; high byte of length = 0 (length < 256) 
  53.     mov     Str1[bx],CR             ; Append Carriage Return
  54.     mov     Str1[bx+1],LF           ; Append Line Feed
  55.     mov     Str1[bx+2],'$'          ; Append End of Message
  56. ;===    Output header and string entered                
  57.     mov     ah,09                   ; function 09 - output text string
  58.     lea     dx,MsgOut               ; address of message 'Text entered'
  59.     int     21h                     ; DOS service call
  60.     lea     dx,Str1                 ; address of string obtained
  61.     int     21h                     ; DOS service call
  62. .exit
  63.     end
  64.